package com.itheima.homework.homework4;

import java.util.ArrayList;
import java.util.Objects;

/**
 * @Author 王加鑫
 * @Date 2021/5/10 19:51
 * @Version 1.0
 */
public class Demo4 {
    public static void main(String[] args) {
        Emloyee emloyee1 = new Emloyee("张三",23);
        Emloyee emloyee2 = new Emloyee("张三",28);
        Emloyee emloyee3 = new Emloyee("李四",24);
        Emloyee emloyee4 = new Emloyee("张三",23);
        ArrayList<Emloyee> emloyees = new ArrayList<>();
        if(emloyees != null){
            emloyees.add(emloyee1);
            emloyees.add(emloyee2);
            emloyees.add(emloyee3);
            emloyees.add(emloyee4);
        }

        for (int i = 0; i < emloyees.size(); i++) {
            System.out.println(emloyees.get(i).toLibao(emloyees));
        }


    }
}

class Emloyee{
    private String name;
    private int age;

    public Emloyee() {
    }

    public Emloyee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Emloyee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Emloyee emloyee = (Emloyee) o;
        return age == emloyee.age &&
                Objects.equals(name, emloyee.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public String getLiBao(ArrayList<Emloyee> emloyees) {
        String s1 = "";
        if(emloyees != null){
            for (int i = 0; i < emloyees.size(); i++) {
                //当集合不为空,且名字和年龄相同的时候就获得了缘分大礼包,否则就获得了普通大礼包
                if (this.name.equals(emloyees.get(i).name) && this.age == emloyees.get(i).age) {
                    s1 = "获得了缘分大礼包";
                } else {
                    s1 = "获得了普通大礼包";
                }
            }
        }
        return s1;

    }
    public String toLibao(ArrayList<Emloyee> emloyees){
        return "Emloyee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}' + getLiBao(emloyees);
    }
}
